package com.sgb.kjwl.view.ui.activity.self.websiteManage;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.graphics.Bitmap;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityWebsiteIntroduce3Binding;

public class WebsiteIntroduceActivity3 extends AppActivity {

    private ActivityWebsiteIntroduce3Binding binding;

    public static void start(Context context,String url){
        Intent intent = new Intent(context,WebsiteIntroduceActivity3.class);
        intent.putExtra("companyUrl",url);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_website_introduce3);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("企业简介");

        WebSettings webSettings = binding.companyWeb.getSettings();
        webSettings.setJavaScriptEnabled(true);
        binding.companyWeb.setWebChromeClient(new WebChromeClient(){

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
            }
        });

        binding.companyWeb.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                super.onReceivedError(view, request, error);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.toString());
                return true;
            }

        });
    }

    @Override
    protected void init() {
        String companyUrl = getIntent().getStringExtra("companyUrl");
        binding.companyWeb.loadData(companyUrl, "text/html", "UTF-8");
    }

    @Override
    protected void onDestroy() {

        binding.companyWeb.clearCache(true);
        binding.companyWeb.removeAllViews();

        super.onDestroy();
    }
}
